#include <osg/GraphicsContext>
#include <osgQt/GraphicsWindowQt>
#include "compositeviewerwidget.h"

CompositeViewerWidget::CompositeViewerWidget(QWidget *parent)
	: QWidget(parent)
{

}

osg::Camera* CompositeViewerWidget::createCamera(int x,int y, int w, int h, const std::string& name="",bool windowDecoration=false)
{
	osg::ref_ptr<osg::DisplaySettings> ds = osg::DisplaySettings::instance().get();

	osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
	traits->x = x;
	traits->y = y;
	traits->width = w;
	traits->height = h;
	traits->doubleBuffer = true;
	traits->windowDecoration = windowDecoration;
	traits->windowName = name;
	traits->alpha = ds->getMinimumNumAlphaBits();
	traits->samples = ds->getNumMultiSamples();
	traits->sampleBuffers = ds->getMultiSamples();
	traits->stencil = ds->getMinimumNumStencilBits();

	osg::ref_ptr<osg::Camera> camera = new osg::Camera;
	camera->setGraphicsContext(new osgQt::GraphicsWindowQt(traits));
    camera->setClearColor(osg::Vec4(0.2,0.2,0.6,1.0));
	camera->setViewport(0,0,traits->width,traits->height);
	camera->setProjectionMatrixAsPerspective(
		30.0f,static_cast<double>(traits->width)/static_cast<double>(traits->height),1.0f,10000.0f);
	
	return camera.release();
}

CompositeViewerWidget::~CompositeViewerWidget()
{

}
